// pages/refundDeatils/refundDeatils.js
const api = require('../../utils/http.js');
const app =getApp();
Page({

	/**
	 * 页面的初始数据
	 */
	data: {
		amount: '1.70',
		refundInfo: {},
		orderId: '',
		uploadImg: []
	},

  //修改申请
	modifyApply() {
		wx.navigateTo({
      url: '/pages/refund/refund?orderId=' + this.data.orderId + '&refundInfo1=' + JSON.stringify(this.data.refundInfo)
		})
	},
	cancelApply() {
    var uid = app.globalData.uid;
    api.fetchApi('procedure_t', {
      p: `R2009004|${uid}|${this.data.orderId}`
		}).then(res => {
			if (res.data.code == 1) {
        if (res.data.results[0].codes==0){
          wx.showToast({
            title: '取消申请成功',
            icon: 'success'
          })

          var pages = getCurrentPages();
          //上一个页面实例对象
          var prePage = pages[pages.length - 2];
          prePage.getOrderDetails();
          setTimeout(()=>{
            wx.navigateBack({
              
            })
          },1500)
        } else if (res.data.results[0].codes == 1){
          wx.showToast({
            title: '已经通过退款',
            icon: 'none'
          })
        } else if (res.data.results[0].codes == -1) {
          wx.showToast({
            title: '已经不通过退款',
            icon: 'none'
          })
        }
				
			} else {
				wx.showToast({
					title: '取消申请失败',
					icon: 'none'
				})
			}
		})
	},
	refundDeatilsAjax() {
		api.fetchApi('procedure_t', {
			p: `R2007005|${this.data.orderId}`
		}).then(res => {
			const {
				code,
				results
			} = res.data
			if (code == 1) {
				this.setData({
					refundInfo: results[0],
					uploadImg: results[0].return_img.split(',')
				})
			} else {
				wx.showToast({
					title: `${res.data.errorMsg}`,
					icon: 'none'
				})
			}
		})
	},
	/**
	 * 生命周期函数--监听页面加载
	 */
	onLoad: function(options) {
		let orderId = options.orderId || ''
		this.setData({
			orderId
		})
		this.refundDeatilsAjax()
	},
	/**
	 * 生命周期函数--监听页面初次渲染完成
	 */
	onReady: function() {

	},

	/**
	 * 生命周期函数--监听页面显示
	 */
	onShow: function() {

	},

	/**
	 * 生命周期函数--监听页面隐藏
	 */
	onHide: function() {

	},

	/**
	 * 生命周期函数--监听页面卸载
	 */
	onUnload: function() {

	},

	/**
	 * 页面相关事件处理函数--监听用户下拉动作
	 */
	onPullDownRefresh: function() {

	},

	/**
	 * 页面上拉触底事件的处理函数
	 */
	onReachBottom: function() {

	},

	/**
	 * 用户点击右上角分享
	 */
	onShareAppMessage: function() {

	}
})
